package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysCheckBoxConvert;
import net.learn.system.convert.SysJudgeConvert;
import net.learn.system.dao.SysJudgeDao;
import net.learn.system.entity.SysCheckBoxEntity;
import net.learn.system.entity.SysJudgeEntity;
import net.learn.system.query.SysCheckBoxQuery;
import net.learn.system.query.SysJudgeQuery;
import net.learn.system.service.SysJudgeService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysCheckBoxVO;
import net.learn.system.vo.SysJudgeVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 李立志
 * @since 2022-04-01
 */
@Service
public class SysJudgeServiceImpl extends BaseServiceImpl<SysJudgeDao, SysJudgeEntity> implements SysJudgeService {
    @Override
    public String addJudge(SysJudgeVO vo){
        SysJudgeEntity entity = SysJudgeConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        baseMapper.insert(entity);
        return uuid;
    }
    @Override
    public Boolean updateJudge(SysJudgeVO vo){
        SysJudgeEntity entity = SysJudgeConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {

        removeByIds(idList);
    }
    @Override
    public List<SysJudgeVO> qryJudgeList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        return baseMapper.selectList(queryWrapper);
    }
    @Override
    public List<SysJudgeVO> qryJudgePaper(SysJudgeQuery qry) {

        return baseMapper.qryJudgePaper(qry);
    }
    @Override
    public List<SysJudgeVO> qryJudgePaperList(SysJudgeQuery qry) {
        return baseMapper.qryJudgePaperList(qry);
    }
    @Override
    public List<SysJudgeVO> qryJudgeRandList(SysJudgeQuery qry) {
        return baseMapper.qryJudgeRandList(qry);
    }
    @Override
    public PageResult<SysJudgeVO> qryJudgeListPage(SysJudgeQuery query) {
        IPage<SysJudgeEntity> page = baseMapper.qryJudgeListPage(getPage(query), query);

        return new PageResult<>(SysJudgeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
    @Override
    public PageResult<SysJudgeVO> qryQuestionJudge(SysJudgeQuery query) {
        IPage<SysJudgeEntity> page = baseMapper.qryQuestionJudge(getPage(query), query);

        return new PageResult<>(SysJudgeConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
